package com.android.fragmentdemo.fragments
import android.content.Intent
import androidx.lifecycle.ViewModelProvider
import android.os.Bundle
import android.provider.Settings
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.android.fragmentdemo.HomePageActivity
import com.android.fragmentdemo.QRCodeActivity
import com.android.fragmentdemo.R
import com.android.fragmentdemo.SecondActivity
import com.android.fragmentdemo.SlipItemActivity
import com.hengfoxwolf.commonbase.base.BaseFragment
import com.android.fragmentdemo.databinding.FragmentFirstPageBinding
import com.android.fragmentdemo.leanback.HGVUseHActivity
import com.android.fragmentdemo.leanback.VGVComposeActivity
import com.android.fragmentdemo.leanback.VGVUseVActivity
import com.android.fragmentdemo.startActivity
import com.hengfoxwolf.commonbase.base.util.LogX

class FirstPageFragment : BaseFragment<FragmentFirstPageBinding>() {

    private lateinit var viewModel: FirstPageViewModel

    override fun getLayoutId() = R.layout.fragment_first_page

    override fun init(savedInstanceState: Bundle?) {
        LogX.init(FirstPageFragment::class.java)
        arguments.let {
            val title = it?.getString(KEY_PARAM) ?: ""
            mBinding.tvTitle.text = title
        }

        mBinding.goOthers.setOnClickListener {
            mContext.startActivity<SecondActivity>()
        }

        mBinding.goViewpage.setOnClickListener {
            mContext.startActivity<HomePageActivity>()
        }

        mBinding.goSlipItem.setOnClickListener {
            mContext.startActivity<SlipItemActivity>()
        }

        mBinding.btnTestVgv.setOnClickListener {
            mContext.startActivity<VGVUseVActivity>()
        }

        mBinding.btnTestHgv.setOnClickListener {
            mContext.startActivity<HGVUseHActivity>()
        }

        mBinding.btnTestComposeHgv.setOnClickListener {
            mContext.startActivity<VGVComposeActivity>()

             //开启无障碍服务
//             val serviceIntent =  Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)
//             serviceIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
//             startActivity(serviceIntent)
        }

        mBinding.btnTestQrcode.setOnClickListener {
            //context?.startActivity<QRCodeActivity>()

            //启动外部activity
            val intent = Intent()
            intent.setClassName(
                "com.hengfoxwolf.kotlincoroutinemvpdemo",
                "com.hengfoxwolf.kotlincoroutinemvpdemo.BaseQuickAdapterActivity")
            mContext.startActivity(intent)
        }

        LogX.d("fragment---override fun init(savedInstanceState: Bundle?)")
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        viewModel = ViewModelProvider(this)[FirstPageViewModel::class.java]
    }

    override fun onResume() {
        super.onResume()
        Log.d(TAG, "111--${TAG}--override fun onResume()")
    }

    companion object {
        private const val TAG = "FirstPageFragment"
        private const val KEY_PARAM = "first_page"

        fun newInstance(param: String): FirstPageFragment {
            val fragment = FirstPageFragment()
            val bundle = Bundle()
            bundle.putString(KEY_PARAM, param)
            fragment.arguments = bundle
            return fragment
        }
    }
}